import requests
import re

# 接口：/status/{codes}; Return status code or random status code if more than one are given
# parameters: codes(path): "xxx,xxx,xxx"

def status_codes(method, codes: str) -> None:
    pattern = r'\b\d{3}\b(, \d{3})*'
    if not re.fullmatch(pattern, codes):
        raise TypeError("codes must be a string with http codes, suchas '200, 304, 404' ")
    url = f'https://httpbin.org/status/{codes}'
    method = method.upper()
    try:
        response = requests.request(method, url)
        print(f"Method {method}, URL: {url}")
        print(f"Response Status Code: {response.status_code}")
    except Exception as e:
        print(f"Error for {method} {url}: {e}")

methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
codes = "200, 201, 301, 304, 403, 502"
for method in methods:
    status_codes(method, codes)